﻿function setProduct(product,color) 
{debugger;
    document.getElementById("ctl00_ContentPlaceHolder1_hdColorCode").value=color;
    var style=document.getElementById("Color"+color).className;
      if(style!="rb_imglj")
      {
          document.getElementById("Amount").value="1";          
          var Color=document.getElementsByTagName("img");
          document.getElementById("Hid_SelectColor").value=color;
            for(var i=0;i<Color.length;i++)
            {
                if(Color[i].id!=null)
                {
                    if(Color[i].id.length>5)
                    {
                        if(Color[i].id.substr(0,5)=="Color")
                        {
                             Color[i].className="";
                        }
                    }
                }
            }
           if(document.getElementById("Color"+color)!=null)
           {
              document.getElementById("Color"+color).className="rb_imglj"; //颜色选中的样式  
           }  
          var pid=document.getElementById("ProductCode").innerHTML; //商品ID
         
          $j.post("../Handler/ProductHandler.ashx", { PID: pid,Color:color},
          function(data){         
            if(data)
            {     
            var arr=new Array();
            arr=data.split("@");     
            var bigsrc=arr[0];
            var partlist=arr[1];
            var kc=arr[3];
            $("#MiddleImage").attr("src",bigsrc);
            $("#psmallimg").html(partlist);
            if(arr.length>=3)
            {
                document.getElementById("Size").innerHTML="尺寸:"+arr[2].toString();
                if(arr[3].length>0)
                {
                    if(parseFloat(arr[3])<1)
                    {
                        document.getElementById("Stock").innerHTML="库存不足";
                    }
                    else
                    {
                        document.getElementById("Stock").innerHTML="";
                    }
                }               
                
            }
            }
            else
            {
                alert("");
            }
        }
    );

      }
setTitle();
}
function setBigImg(pname)  //点击局部图时更新大图
{
    var BigImag=document.getElementById("MiddleImage");    
    var aa=BigImag.src;       
    var first=aa.lastIndexOf('_');    
    var last=aa.lastIndexOf('.');     
    var name=aa.substr(first+1,last-first-1);   
    if(name!=pname)
    {
        var middleImg = aa.substr(0,first+1)+pname+aa.substr(last,aa.length-last);
        showMirror(middleImg);
        var part=document.getElementsByTagName("li");
            for(var i=0;i<part.length;i++)
            {
                if(part[i].id!=null)
                {
                    if(part[i].id.length>4)
                    {
                        if(part[i].id.substr(0,4)=="Part")
                            {
                                 part[i].className="";
                            }
                    }
                }
            }
        if(document.getElementById("Part"+pname)!=null)
        {
            document.getElementById("Part"+pname).className="rb_imglj"; //切换局部图时设定样式.
        }
    }
}
function showMirror(middleImg)
{
    if(middleImg)
    {
        middleImg = middleImg.toLowerCase();
        document.getElementById("MiddleImage").src = middleImg;
        $("#MiddleImage").hide().fadeIn('slow');
    }
}
function ShowBigImg()
{
    var middleImg=$("#MiddleImage").attr("src");
    if(middleImg)
    {
        var bigImg = middleImg.replace("big", "show");
        window.open(bigImg);
    }

}
function PageInit()
{
    var member=document.getElementById("MemberPrice"); 
    var login=document.getElementById("login");
    var zk=document.getElementById("Hid_ZK");
    var GObuy=document.getElementById("GOBUY");
    var GoCollect=document.getElementById("GoCollect");
    var price=$("#DPJ").html();
    if(zk.value.length>0)
    {
        var M_Price=0.0;
        M_Price=(parseFloat(price)*parseFloat(zk.value));
        member.innerHTML=M_Price.toFixed(2);
        member.style.display="block";
        login.style.display="none";
        GObuy.href="javascript:addCart()";
        GoCollect.href="javascript:AddCollect()";
    }
    else
    {
        member.innerHTML=price;
        member.style.display="none";
        login.style.display="block";
        GObuy.href="../Users/login.aspx";
        GoCollect.href="../Users/login.aspx";
    }
}
